import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import postCssPxToRem from "postcss-pxtorem"
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue()
    ],
    // 适配
    css: {
        postcss: {
            plugins: [
                postCssPxToRem({
                    rootValue: 37.5, // 1rem的大小
                    propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
                })
            ]
        },
        // css预处理器
        preprocessorOptions: {
            less: {
                charset: false,
                additionalData: '@import "./src/assets/global.less";',
            },
        }
    },
    // 配置别名
    resolve: {
        alias: {
            '@': resolve(__dirname, "src"),
        },
        extensions: [".ts", ".js", ".jsx", ".tsx"], // 导入时想要省略的扩展名列表。
    },
    // 配置代理
    server: {
        proxy: {
            // 选项写法
            '/app': {
                target: 'https://m.you.163.com',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/app/, '')
            },
            '/sph': {
                target: 'http://sph-h5-api.atguigu.cn',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/sph/, '')
            }
        }
    }
})
